home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
et
/
src
/
math.c
< prev
next >
Wrap
Text File
|
1993-07-08
|
11KB
|
442 lines
#include "et.h"
void make_name(void)/*et*/
{
int p_i, q_i, i;
unsigned f, h, u, v, k, n, *buf_p, *icn_p;
VRAM *vram_p;
char *c_p, *s_p;
f = test_bit(G_f, f_SV|f_GPH|f_VIEW|f_EE|f_TT);
if (test_bit(G_f, f_SV|f_GPH)) {
if (test_bit(G_f, f_SS)) {
copy_edge(STORE, AFT);
i = 0;
res_bit(G_f, f);
go_bar(&i, 7, 0);
set_bit(G_f, f);
draw_frame3(P_i[i_WIN_VIEW]);
copy_edge(RESTORE, AFT);
} else if (test_bit(G_f, f_EE)) {
cls_view(P_i[i_WIN_VIEW]);
res_bit(G_f, f);
cul_edge(G_et, G_edge, G_nb.edge, 0, ENT);
set_bit(G_f, f);
draw_frame3(P_i[i_WIN_VIEW]);
}
}
buf_p = P_v[v_ICN];
icn_p = P_v[v_VRAM];
p_i = P_i[i_WIN_VIEW][0];
q_i = P_i[i_WIN_VIEW][1];
vram_p = vram_addr(p_i, q_i, !G_nb.page);
if (test_bit(G_f, f_AA))
s_p = P_c[c_COL_A];
else if (test_bit(G_f, f_NN))
s_p = P_c[c_COL_G];
else
s_p = P_c[c_COL_N];
while (1) {
c_p = s_p;
v = n = 0;
while (1) {
for (u = *c_p; u; u <<= 4) {
k = _peek_longword(0x120, (int)vram_p);
if (k)
for (h = *c_p; h; h <<=4 )
if (test_bit(k, h) == h) {
v |= u;
break;
}
vram_p++;
}
if (!*(++c_p))
break;
vram_p -= 8;
}
*icn_p++ = v;
p_i += 64;
if (p_i < P_i[i_WIN_VIEW][2])
continue;
p_i = P_i[i_WIN_VIEW][0];
q_i++;
if (q_i < P_i[i_WIN_VIEW][3])
vram_p = vram_addr(p_i, q_i, !G_nb.page);
else
break;
}
k = P_i[i_SIZE_ICN][2];
vram_p = P_v[v_VRAM];
while (1) {
v = 0;
for (u = 8; u; u--, vram_p += P_i[i_SIZE_ICN][2])
v |= *vram_p;
*buf_p++ = v;
if (--k)
vram_p -= P_i[i_SIZE_ICN][2] * 8;
else {
vram_p -= P_i[i_SIZE_ICN][2];
k = P_i[i_SIZE_ICN][2];
}
vram_p++;
if (buf_p >= P_v[v_ICN] + P_i[i_SIZE_ICN][2] * P_i[i_SIZE_ICN][3])
break;
}
}
void exg_xyz(int *zyx_p, int *xyz_p)/*et*/
{
int i;
for (i = 3; i; i--) {
*zyx_p = *xyz_p;
xyz_p += 2;
zyx_p += 2;
}
}
int cmp_xyz(char *xyz_p, int k)/*et*/
{
int i, j;
char *buf_p, *c_p;
for (i = 1, j = 0; j < k && i; j++) {
c_p = xyz_p;
buf_p = (char*)((int)G_bf.et_buf + j * sizeof(ET));
for (i = sizeof(ET); i; i--)
if (*c_p++ != *buf_p++)
break;
}
if (!i)
if (test_bit(G_f, f_NN)) {
j--;
buf_p = G_bf.et_buf + (int)j * sizeof(ET);
_copy_buf(buf_p, (void*)((int)buf_p + sizeof(ET)), (k-j-1)*sizeof(ET));
}
return(i);
}
int make_pna(char *pna_p)/*et*/
{
FILE *File, *Temp;
int edge_i, mv;
char *s_p, *val_p, s_a[1000], val_a[10];
ET Et[1];
int i, j, k, h, u, f, cut, cut_b, key_i;
int *buf_p;
res_bit(G_f, f_RR);
set_file_i(&P_c[c_FILE_BAK][8], 3);
if (test_bit(G_f, f_REPLAY)) {
cut_b = read_replay(0);
key_i = read_replay(0);
}
Temp = et_fopen(P_c[c_FILE_BAK], "wb", NULL);
G_nb.drive = *P_c[c_FILE_BAK];
File = et_fopen(pna_p, "rb", Temp);
edge_i = 0;
et_fwrite(&edge_i, sizeof(int), 1, Temp);
f = 0;
u = 0;
G_nb.edge = 0;
while (fgets(s_a, 999, File)) {
if (!test_bit(G_f, f_REPLAY))
MOS_rdpos(&u, &i, &i);
else
if (key_i == edge_i)
u = cut_b;
else
inkey(SCAN);
if (u)
break;
if (*s_a == 'p') {
if (!f) {
j = 0;
f = 1;
buf_p = (int*)G_bf.et_buf;
}
s_p = &s_a[11];
for (i = 3; i; i--) {
val_p = val_a;
while (*s_p != ' ' && *s_p != '.' && *s_p != 0x0d)
*val_p++ = *s_p++;
*val_p = '\0';
mv = atoi(val_a)*GETA_ET;
if (i == 2)
mv = -mv;
*buf_p++ = mv;
while (*s_p++ != ' ' && *s_p != 0x0d)
;
}
j++;
} else {
if (!f)
continue;
f = 0;
buf_p = (int*)G_bf.et_buf;
G_nb.edge = 1;
for (i = k = 0; i < j-1; i++, k += 3) {
Et->xyz[0] = buf_p[k];
Et->xyz[1] = buf_p[k+3];
Et->xyz[2] = buf_p[k+1];
Et->xyz[3] = buf_p[k+4];
Et->xyz[4] = buf_p[k+2];
Et->xyz[5] = buf_p[k+5];
et_fwrite(Et, sizeof(ET), 1, Temp);
for (h = 2; h; h--, exchange_page())
if (test_bit(G_f, f_SV|f_GPH)) {
cul_edge(Et, G_edge, 1, _LT, h);
cul_edge(Et, G_bf.edge, 1, _RT, h);
} else
cul_edge(Et, G_edge, 1, 0, h);
edge_i++;
}
Et->xyz[0] = buf_p[k];
Et->xyz[1] = buf_p[0];
Et->xyz[2] = buf_p[k+1];
Et->xyz[3] = buf_p[1];
Et->xyz[4] = buf_p[k+2];
Et->xyz[5] = buf_p[2];
et_fwrite(Et, sizeof(ET), 1, Temp);
for (h = 2; h; h--, exchange_page())
if (test_bit(G_f, f_SV|f_GPH)) {
cul_edge(Et, G_edge, 1, _LT, h);
cul_edge(Et, G_bf.edge, 1, _RT, h);
} else
cul_edge(Et, G_edge, 1, 0, h);
edge_i++;
}
}
if (u != 2) {
fseek(Temp, 0L, 0);
et_fwrite(&edge_i, sizeof(int), 1, Temp);
}
fclose(File);
fclose(Temp);
switch(u) {
case 0:
cut = 0;
break;
case 1:
cut = _RET;
break;
case 2:
cut = _ESC;
break;
}
draw_cut(cut);
if (u) {
if (!test_bit(G_f, f_REPLAY)) {
write_replay(u);
write_replay(edge_i);
}
if (u == 2)
unlink(P_c[c_FILE_BAK]);
else
u = 0;
} else
if (!test_bit(G_f, f_REPLAY)) {
write_replay(0);
write_replay(-1);
}
return((u) ? _ESC : _RET);
}
void clip_pq(int pq_a[], unsigned *f1_p, unsigned *f2_p, int xv_l, int xv_r, int i)/*et*/
{
unsigned *f_p;
int p_d, q_d;
int *p1_p, *q1_p, *p2_p, *q2_p;
f_p = (i) ? f2_p : f1_p;
p1_p = &pq_a[i*2];
q1_p = p1_p+1;
p2_p = &pq_a[!i*2];
q2_p = p2_p+1;
p_d = *p2_p - *p1_p;
q_d = *q2_p - *q1_p;
if (*f_p & 1) {
*f_p &= ~1;
*q1_p = q_d * (xv_l - *p1_p) / p_d + *q1_p;
*p1_p = xv_l;
} else if (*f_p & 2) {
*f_p &= ~2;
*q1_p = q_d*(xv_r-1 - *p1_p) / p_d + *q1_p;
*p1_p = xv_r - 1;
}
if (*f_p & 4) {
*f_p &= ~4;
*p1_p = p_d * (-G_vi.y - *q1_p) / q_d + *p1_p;
*q1_p = -G_vi.y;
} else if (*f_p & 8) {
*f_p &= ~8;
*p1_p = p_d * (G_vi.y-1 - *q1_p) / q_d + *p1_p;
*q1_p = G_vi.y - 1;
}
if (*p1_p < xv_l)
*f_p |= 1;
else if (*p1_p >= xv_r)
*f_p |= 2;
if (*q1_p < -G_vi.y)
*f_p |= 4;
else if (*q1_p >= G_vi.y)
*f_p |= 8;
}
int move_et(int n, int key_i)/*et*/
{
int i, j, k;
j = G_pm.i.angle;
k = 0;
switch(n) {
case 1:
G_ps.x += (int)G_pm.i.x_step * GETA_ET;
break;
case 2:
G_ps.x -= (int)G_pm.i.x_step * GETA_ET;
break;
case 3:
G_ps.y += (int)G_pm.i.y_step * GETA_ET;
break;
case 4:
G_ps.y -= (int)G_pm.i.y_step * GETA_ET;
break;
case 5:
G_ps.z += (int)G_pm.i.z_step * GETA_ET;
break;
case 6:
G_ps.z -= (int)G_pm.i.z_step * GETA_ET;
break;
case 7:
j = 90;
case 13:
G_ps.x_g += j;
x_rot((int)icos(j), -(int)isin(j));
break;
case 8:
j = 90;
case 14:
G_ps.x_g -= j;
x_rot((int)icos(j), (int)isin(j));
break;
case 9:
j = 90;
case 15:
G_ps.y_g += j;
y_rot((int)icos(j), -(int)isin(j));
break;
case 10:
j = 90;
case 16:
G_ps.y_g -= j;
y_rot((int)icos(j), (int)isin(j));
break;
case 11:
j = 90;
case 17:
G_ps.z_g -= j;
z_rot((int)icos(j), (int)isin(j));
break;
case 12:
j = 90;
case 18:
G_ps.z_g += j;
z_rot((int)icos(j), -(int)isin(j));
break;
case 19:
case 20:
if (test_bit(G_f, f_TROFF)) {
res_bit(G_f, f_TROFF);
if (test_bit(G_f, f_FF))
set_bit(G_f, f_TRON);
} else {
set_bit(G_f, f_TROFF);
if (test_bit(G_f, f_FF))
res_bit(G_f, f_TRON);
}
k = _TAB;
break;
case 21:
case 22:
if (test_bit(G_f, f_REV))
res_bit(G_f, f_REV);
else
set_bit(G_f, f_REV);
if (!test_bit(G_f, f_BLIND)) {
draw_edge(P_SET, AFT);
for (i = 2; i; i--, exchange_page())
mark_rev();
draw_edge(P_RES, AFT);
}
k = _INS;
break;
case 23:
case 24:
G_nb.edge_b = G_nb.edge;
do {
G_pn.csr++;
} while (EOC != *G_pn.csr && *G_pn.csr == G_nb.et);
if (EOC != *G_pn.csr) {
G_nb.et = *G_pn.csr;
load_et(G_nb.et, 1);
if (test_bit(G_f, f_SV|f_GPH)) {
if (!test_bit(G_f, f_EE)) {
copy_edge(STORE, BEF);
cul_edge(G_et, G_edge, G_nb.edge, _LT, 0);
cul_edge(G_et, G_bf.edge, G_nb.edge, _RT, 0);
if (!test_bit(G_f, f_BLIND)) {
exchange_page();
copy_edge(RESTORE, BEF);
draw_edge(P_RES, BEF);
set_bit(G_f, f_BLIND);
cul_edge(G_et, G_edge, G_nb.edge, _LT, 0);
cul_edge(G_et, G_bf.edge, G_nb.edge, _RT, 0);
res_bit(G_f, f_BLIND);
}
}
} else {
_copy_buf(G_bf.edge, G_edge, sizeof(EDGE)*G_nb.edge_b);
if (!test_bit(G_f, f_EE)) {
cul_edge(G_et, G_edge, G_nb.edge, 0, 0);
if (!test_bit(G_f, f_BLIND)) {
exchange_page();
draw_edge(P_RES, BEF);
}
}
}
G_nb.edge_b = G_nb.edge;
}
k = S_RET;
break;
default:
break;
}
G_mv[key_i++].key = n;
if (!test_bit(G_f, f_SPLINE)) {
G_mv[key_i].x = G_ps.x;
G_mv[key_i].y = G_ps.y;
G_mv[key_i].z = G_ps.z;
}
if (!test_bit(G_f, f_RR))
G_mv[key_i].r = G_pm.i.r;
G_nb.key_i = key_i;
return(k);
}
void set_flag(unsigned *f1_p, unsigned *f2_p, int pq_a[], int xv_l, int xv_r)/*et*/
{
*f1_p = 0;
if (pq_a[0] < xv_l)
*f1_p |= 1;
else if (pq_a[0] >= xv_r)
*f1_p |= 2;
if (pq_a[1] < -G_vi.y)
*f1_p |= 4;
else if (pq_a[1] >= G_vi.y)
*f1_p |= 8;
*f2_p = 0;
if (pq_a[2] < xv_l)
*f2_p |= 1;
else if (pq_a[2] >= xv_r)
*f2_p |= 2;
if (pq_a[3] < -G_vi.y)
*f2_p |= 4;
else if (pq_a[3] >= G_vi.y)
*f2_p |= 8;
}